Ext.define('DCApp.view.img.ListController', {
    extend: 'DCApp.controller.ListController',
    alias: 'controller.imglist',

    onUpload:function(btn){
    	var ff = btn.up('toolbar').down('filefield');
    	var vf = ff.getValue();
    	if(vf==''){
    		Ext.MessageBox.alert('操作提示', '请先选择待上传附件',
        			null, this);
    	}
    	var vw = this.getView();
    	var dv = vw.down('[xtype="attachview"]');
    	var st = dv.getStore();
    	var pos1=vf.lastIndexOf('.');
    	var pos2=vf.lastIndexOf('\\');
    	if(pos2==-1)
    		pos2=vf.lastIndexOf('/');
    	var rec = new DCApp.model.CeAttachment({
    		id:new Date().getTime(),
    		name:vf.substring(pos2+1,pos1-1),
    		suffix:vf.substring(pos1+1)
    	});
    	//st.add(rec);
    	st.insert(0, rec);

    },
    onRel:function(btn){
    	var vw = this.getView();
    	var dv = vw.down('[xtype="attachview"]');
    	var ds = dv.getStore();
    	ds.on('datachanged',function(d,opt){
    		dv.refresh();
    	});
    	var data = this.getViewModel().getData();
        var win = new Ext.window.Window({
        	width:500,
        	height:300,
        	layout:'fit',
        	modal:true,
        	viewModel: this.getViewModel(),
        	items:[{
        		 fieldName: 'name',
        		 xtype: 'multiselector',
        		 title:'选择附件',
        		 //bind:dv.getBind(),
        		 store:ds,
                 search: {
                	 field: 'name',
                     store: {
                         model: 'CeAttachment'
                     }
                 }
        		}
        	],   
        	plain: true,
            headerPosition: 'bottom'
        });
        win.show();    	
    }

});
